"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _jsxRuntime = require("react/jsx-runtime");

var _antdV = require("antd-v4");

var _classnames = _interopRequireDefault(require("classnames"));

var _react = require("react");

var _utils = require("../../utils/utils");

var _SiderMenu = require("../SiderMenu/SiderMenu");

var _TopNavHeader = _interopRequireDefault(require("../TopNavHeader"));

require("./index.less");

var renderLogo = function renderLogo(menuHeaderRender, logoDom) {
  if (menuHeaderRender === false) {
    return null;
  }

  if (menuHeaderRender) {
    return menuHeaderRender(logoDom, null);
  }

  return logoDom;
};

var GlobalHeader = function GlobalHeader(props) {
  var isMobile = props.isMobile,
      logo = props.logo,
      collapsed = props.collapsed,
      onCollapse = props.onCollapse,
      _props$collapsedButto = props.collapsedButtonRender,
      collapsedButtonRender = _props$collapsedButto === void 0 ? _SiderMenu.defaultRenderCollapsedButton : _props$collapsedButto,
      rightContentRender = props.rightContentRender,
      menuHeaderRender = props.menuHeaderRender,
      onMenuHeaderClick = props.onMenuHeaderClick,
      propClassName = props.className,
      style = props.style,
      layout = props.layout,
      children = props.children,
      _props$headerTheme = props.headerTheme,
      headerTheme = _props$headerTheme === void 0 ? 'dark' : _props$headerTheme,
      splitMenus = props.splitMenus,
      menuData = props.menuData,
      prefixCls = props.prefixCls;

  var _useContext = (0, _react.useContext)(_antdV.ConfigProvider.ConfigContext),
      direction = _useContext.direction;

  var baseClassName = "".concat(prefixCls, "-global-header");
  var className = (0, _classnames.default)(propClassName, baseClassName, (0, _defineProperty2.default)({}, "".concat(baseClassName, "-layout-").concat(layout), layout && headerTheme === 'dark'));

  if (layout === 'mix' && !isMobile && splitMenus) {
    var noChildrenMenuData = (menuData || []).map(function (item) {
      return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
        children: undefined,
        routes: undefined
      });
    });
    var clearMenuData = (0, _utils.clearMenuItem)(noChildrenMenuData);
    return (0, _jsxRuntime.jsx)(_TopNavHeader.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({
      mode: "horizontal"
    }, props), {}, {
      splitMenus: false,
      menuData: clearMenuData,
      theme: headerTheme
    }));
  }

  var logoClassNames = (0, _classnames.default)("".concat(baseClassName, "-logo"), (0, _defineProperty2.default)({}, "".concat(baseClassName, "-logo-rtl"), direction === 'rtl'));
  var logoDom = (0, _jsxRuntime.jsx)("span", {
    className: logoClassNames,
    children: (0, _jsxRuntime.jsx)("a", {
      children: (0, _SiderMenu.defaultRenderLogo)(logo)
    })
  }, "logo");
  return (0, _jsxRuntime.jsxs)("div", {
    className: className,
    style: (0, _objectSpread2.default)({}, style),
    children: [isMobile && renderLogo(menuHeaderRender, logoDom), isMobile && collapsedButtonRender && (0, _jsxRuntime.jsx)("span", {
      className: "".concat(baseClassName, "-collapsed-button"),
      onClick: function onClick() {
        if (onCollapse) {
          onCollapse(!collapsed);
        }
      },
      children: collapsedButtonRender(collapsed)
    }), layout === 'mix' && !isMobile && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: (0, _jsxRuntime.jsx)("div", {
        className: logoClassNames,
        onClick: onMenuHeaderClick,
        children: (0, _SiderMenu.defaultRenderLogoAndTitle)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
          collapsed: false
        }), 'headerTitleRender')
      })
    }), (0, _jsxRuntime.jsx)("div", {
      style: {
        flex: 1
      },
      children: children
    }), rightContentRender && rightContentRender(props)]
  });
};

var _default = GlobalHeader;
exports.default = _default;